﻿@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<fieldset class="table-fieldset" id="searchfield" style="display:none">
    <legend style="color:darkgrey">快速查询</legend>
    <div style="margin: 5px 5px 5px 5px">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input type="text" name="tbId" id="tbId" placeholder="录入表..." class="layui-input">
                </div>
                <div class="layui-inline">
                    <input type="text" name="listId" id="listId" placeholder="主键..." class="layui-input">
                </div>
                <div class="layui-inline">
                    <input type="text" name="key" id="key" placeholder="关键字..." class="layui-input">
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" id="search"><i class="layui-icon layui-icon-search"></i></button>
                    <button type='reset' class='layui-btn layui-btn-primary'><i class='layui-icon layui-icon-refresh'></i></button>
                </div>
            </div>
        </form>
    </div>
</fieldset>
<!--数据表格-->
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>

<script>
    layui.use(["table", "form", "exLayer", "exUtils"], function () {
        let table = layui.table;
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let $ = layui.$;

        form.render(); //

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/Record/RecordErr/GetList?key=" + $("#key").val() + "&tbId=" + $("#tbId").val() + "&listId=" + $("#listId").val(),
            limits: [100, 200],
            limit: 100,
            page: true,
            method: "post",
            defaultToolbar: [{ title: '搜索', layEvent: 'searchShow', icon: 'layui-bg-blue layui-icon-search' }, 'filter', 'exports'],
            toolbar: "#toolbarTpl",
            cols: [[
                { type: "checkbox", fixed: 'left' },
                { type: "numbers", title: "NO.", fixed: 'left' },
                { field: "TbId", title: "录入表", sort: true, width: 120 },
                { field: "ListId", title: "主键", width: 120, sort: true },
                { field: "OperateTime", title: "时间", width: 150, sort: true },
                { field: "Info", title: "说明", width: layui.device().mobile ? 250 : null },
            ]],
            done: function (res, curr, count) {
            }
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "refresh":
                    refresh();
                    break;
                case "searchShow":
                    searchShow();
                    break;
                case "batchDel":
                    batchDel();
                    break;
            }
        });

        //查询
        $("#search").click(function () {
            search();
        });

        function refresh() {
            ThisTable.reload({
                url: "/Record/RecordErr/GetList?key=" + $("#key").val() + "&tbId=" + $("#tbId").val() + "&listId=" + $("#listId").val()
            });
        }

        function searchShow() {
            var display = $('#searchfield').css('display');
            if (display == 'none') {
                $("#searchfield").show();
                document.body.scrollTop = document.documentElement.scrollTop = 0;
            }
            else {
                $("#searchfield").hide();
            }
        }

        function search() {
            $("#searchfield").hide();
            ThisTable.reload({
                where: { key: $("#key").val(), userId: $("#userId").val(), tbId: $("#tbId").val(), listId: $("#listId").val() },
                page: { curr: 1 }
            });
            return false;
        }

        function batchDel() {
            var idsStr = "";
            var checkStatus = table.checkStatus("tableId");
            var rows = checkStatus.data.length;
            if (rows > 0) {
                for (var i = 0; i < checkStatus.data.length; i++) {
                    idsStr += checkStatus.data[i].Id + ",";
                }
                exLayer.confirm("确定要删除吗？", function (index) {
                    layer.close(index);
                    if (idsStr) {
                        exUtils.ajax("/Record/RecordErr/BatchDel", "post", { idsStr: idsStr, fwid: $("#_fwid").val() }, true).done(function (response) {
                            ThisTable.reload({
                                url: "/Record/RecordErr/GetList?key=" + $("#key").val() + "&tbId=" + $("#tbId").val() + "&listId=" + $("#listId").val()
                            });
                        }).fail(function (error) {
                            console.log(error);
                        });
                    }
                });
            }
            else {
                layer.msg("未选择有效数据");
            }
        }
    });
</script>
<script type="text/html" id="toolbarTpl">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="batchDel" id="batchDel"><i class="fa fa-trash-o"></i>批量删除</button>
    </div>
</script>